<!DOCTYPE html>
<html lang="en">
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/admin/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>

</head>
<body>


<body class="layui-layout-body">
<div class="layui-row">
    <div class="layui-col-md2  formbox " style="margin-top: 10px">

    </div>

    <div class="layui-fluid layui-col-md8 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">
                <form class="layui-form" action="" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">旧密码:</label>
                        <div class="layui-input-block">
                            <input type="password"  name="oldpassword" id="oldpassword" required lay-verify="mainBoard" placeholder=""
                                   autocomplete="off" style="width: 500px" class="layui-input">
                        </div>


                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码:</label>
                        <div class="layui-input-block">
                            <input type="password"  name="password" id="password"
                                   class="layui-input" style="width: 500px">

                            </input>

                        </div>
                    </div>




                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button type="button" class="layui-btn" id="xg"  style="margin-left:10%;width: 200px">
                                    修改
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="layui-col-md2 formbox">

    </div>
</div>
</body>

<script >
    var $ = layui.$;
    $("#xg").click(()=>{
        var oldPasword = $("#oldpassword").val();
        var newPassword = $("#password").val();
        if (oldPasword==null || oldPasword=="")
        {
            layer.msg('旧密码不能为空',{icon:2,time:1500});
            return false;
        }

        if (newPassword==null || newPassword=="")
        {
            layer.msg('新密码不能为空',{icon:2,time:1500});
            return false;
        }

        $.ajax({
            url: "/admin/updateAdmin",
            data: {
                "oldpassword": oldPasword,
                "password": newPassword
            },
            success: (res) => {
                //账号过时，重新登录
                if(res.code==403){
                    layer.msg('拒绝访问',{icon:2,time:1500});
                    return false;
                }
                if(res.code==500){
                    layer.msg('旧密码不正确',{icon:2,time:1500});
                    return false;
                }

                layer.msg('修改成功',{icon:1,time:1500},function () {
                    top.location='/admin/main.html';
                });

            },
            error:(res)=>{
                layer.msg('系统异常,请检查网络或联系管理员');

            }
        });
    })
</script>
</html>